package Homework01;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class work09 {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        Collections.addAll(list, "张无忌,15","周芷若,14","赵敏,13","张三丰,100","张翠山,40","张梁,39");
		/*(1)集合中存储一些字符串的数据，比如：张三，23
		把它收集到的Student类型的数组当中*/
        Student[] arr=new Student[list.size()];
        for(int i=0;i<list.size();i++){
            String[] part=list.get(i).split(",");
            String name=part[0];
            int age=Integer.parseInt(part[1]);

            Student student=new Student(name,age);
            arr[i]=student;
        }
        System.out.println(Arrays.toString(arr));

		/*(2)创建集合添加学生对象，学生对象属性name,age
		  只获取姓名并放到数组当中
		String[] name=new String[list.size()];

		for(int i=0;i<list.size();i++){
			String[] part=list.get(i).split(",");
			name[i]=part[0];
		}
		System.out.println(Arrays.toString(name));*/

		/*(3)创建集合添加学生对象，学生对象属性name,age
		把姓名和年龄拼接成：张三-23的字符串，并放到数组当中
		String[] people=new String[list.size()];
		for(int i=0;i<list.size();i++){
			String[] part=list.get(i).split(",");
			people[i]=(part[0]+"-"+part[1]);
		}
		System.out.println(Arrays.toString(people));*/
    }
}
